import { observer, useLocalObservable } from 'mobx-react'
import styles from './index.module.less'
import Store from '../store'
import { useEffect } from 'react'
import IconFont from '@/components/IconFont'
import { history } from 'umi'
import ScrollListView from '@/components/ScrollListView'
import { api } from '@/servers/api'
import { getData } from '@/servers/http'

const idTextMap = new Map([
    ['8', 'MBTI职业性格'],
    ['25', '霍兰德职业兴趣'],
    ['26', '专业能力'],
    ['27', '核心通用能力'],
    ['28', '发展型能力'],
    ['29', '压力知觉测试'],
])

export default observer(() => {
    const store = useLocalObservable(() => Store)
    useEffect(() => {
        // getTestEvalsRecordList()
        document.title = '测评结果'
    }, [])

    const handleClick = (data: any) => {
        switch (data?.testEval?.type) {
            case '1':
                history.push(`/measurements/result?eval_id=${data.id}&view=1`)
                break
            case '2':
                history.push(`/measurements/result?eval_id=${data.id}&view=1`)
                break
            case '3':
                history.push(`/job/result/${data.id}`)
                break
            case '4':
                history.push(`/evaluation/result/${data.id}`)
                break

            default:
                break
        }
    }

    return (
        <div className={styles.container}>
            <div className={styles.title}>测评结果</div>
            <ScrollListView
                requestApi={data => getData(api.testEvalsRecordList, data)}
                noDataText={
                    <div className={styles.no_data}>
                        空空如也
                        <br />
                        赶紧开始开启测评获取测评结果吧~
                    </div>
                }
                render={data => {
                    return (
                        <div>
                            {data.map((item: any, idx: number) => {
                                return (
                                    <div className={styles.row_item} key={item.id} onClick={() => handleClick(item)}>
                                        <span className={styles.list_no}>{idx + 1}.</span>
                                        <span className={styles.list_time}>{item.create_time}</span>
                                        <span className={styles.list_type}>{idTextMap.get(item.eval_id)}</span>
                                        <IconFont type="icon-zuojiantou" />
                                    </div>
                                )
                            })}
                        </div>
                    )
                }}
            />
        </div>
    )
})
